package com.example.message;

import org.apache.mina.core.session.IoSession;

import java.io.Serializable;


/****
 * 包装消息内容
 */
public class JmsMessageWrapper implements Serializable {

    private IoSession ioSession;

    //消息对应名称
    private String name;

    //是否是队列
    private boolean isQueue;

    //消息内容
    private Object message;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isQueue() {
        return isQueue;
    }

    public void setQueue(boolean queue) {
        isQueue = queue;
    }

    public Object getMessage() {
        return message;
    }

    public void setMessage(Object message) {
        this.message = message;
    }

    public IoSession getIoSession() {
        return ioSession;
    }

    public void setIoSession(IoSession ioSession) {
        this.ioSession = ioSession;
    }

    //确认消息
    public void acknowledge(){
        Request ackRequest = new Request();
        ackRequest.setType(RequestType.ACK);
        ackRequest.setData(((Request) message).getId());
        ioSession.write(ackRequest);
    }

    public JmsMessageWrapper(String name, boolean isQueue , Object message) {
        this.name = name;
        this.isQueue = isQueue;
        this.message = message;
    }
}
